#include <iostream>
#include <vector>
#include <string>
#include <cmath>

bool norm(int d) {
    for (int i = 2; i < d; i++) {
        if (d % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::vector<int> z;
    std::string a;
    std::getline(std::cin, a);
    std::vector<std::string> b;
    std::string temp = "";
    for (char c : a) {
        if (c == ' ') {
            b.push_back(temp);
            temp = "";
        } else {
            temp += c;
        }
    }
    b.push_back(temp);

    if (b[0] == "zero" || b[0] == "one" || b[0] == "two" || b[0] == "three" || b[0] == "four" || b[0] == "five" || b[0] == "six" || b[0] == "seven" || b[0] == "eight" || b[0] == "nine") {
        z.push_back(b[0] == "zero" ? 0 : b[0] == "one" ? 1 : b[0] == "two" ? 2 : b[0] == "three" ? 3 : b[0] == "four" ? 4 : b[0] == "five" ? 5 : b[0] == "six" ? 6 : b[0] == "seven" ? 7 : b[0] == "eight" ? 8 : 9);
    } else {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }

    if (b[1] == "zero" || b[1] == "one" || b[1] == "two" || b[1] == "three" || b[1] == "four" || b[1] == "five" || b[1] == "six" || b[1] == "seven" || b[1] == "eight" || b[1] == "nine") {
        z.push_back(b[1] == "zero" ? 0 : b[1] == "one" ? 1 : b[1] == "two" ? 2 : b[1] == "three" ? 3 : b[1] == "four" ? 4 : b[1] == "five" ? 5 : b[1] == "six" ? 6 : b[1] == "seven" ? 7 : b[1] == "eight" ? 8 : 9);
    } else {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }

    if (b[2] == "zero" || b[2] == "one" || b[2] == "two" || b[2] == "three" || b[2] == "four" || b[2] == "five" || b[2] == "six" || b[2] == "seven" || b[2] == "eight" || b[2] == "nine") {
        z.push_back(b[2] == "zero" ? 0 : b[2] == "one" ? 1 : b[2] == "two" ? 2 : b[2] == "three" ? 3 : b[2] == "four" ? 4 : b[2] == "five" ? 5 : b[2] == "six" ? 6 : b[2] == "seven" ? 7 : b[2] == "eight" ? 8 : 9);
    } else {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }

    int d = z[0] * 100 + z[1] * 10 + z[2];
    int e = d, f = d;

    while (!norm(e)) {
        e--;
    }

    while (!norm(f)) {
        f++;
    }

    if (d - e > f - d) {
        std::cout << f << std::endl;
    } else {
        std::cout << e << std::endl;
    }

    return 0;
}
